package com.flycent.hqhs.ui;

import java.util.List;

import net.tsz.afinal.FinalDb;
import android.content.Context;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.flycent.hqhs.App;
import com.flycent.hqhs.R;
import com.flycent.hqhs.bean.PurchaseProduct;
import com.flycent.hqhs.ui.view.AbsViewHolderAdapter;
import com.nostra13.universalimageloader.core.ImageLoader;

/**
 * @author fbl
 *  商品清单
 */
public class SubmitOrderListActivity extends BackableTitleBarActivity{
	private ListView mList;
	private SubmitOrderListAdapter mAdapter;
	FinalDb db;
	private List<PurchaseProduct> mProducts;
	
	@Override
	protected void onCreate(Bundle savedInstance) {
		super.onCreate(savedInstance);
		setContentView(R.layout.activity_submit_order_list);
		getTitleBar().setTitle("商品清单");
		db = ((App) getApplication()).finalDb;
		
		mList  = (ListView) findViewById(R.id.submit_order_list);
		mAdapter = new SubmitOrderListAdapter(this, R.layout.item_submit_order_list);
		mList.setAdapter(mAdapter);
		
		mProducts = db.findAll(PurchaseProduct.class);
		mAdapter.update(mProducts);
		
	}
	
	
	public class SubmitOrderListAdapter extends AbsViewHolderAdapter<PurchaseProduct>{

		public SubmitOrderListAdapter(Context context, int layoutRes) {
			super(context, layoutRes);
		}

		@Override
		protected void bindData(int pos, PurchaseProduct itemData) {
			ImageView image = getViewFromHolder(R.id.item_submit_order_product_img);
			TextView  text1 = getViewFromHolder(R.id.item_submit_order_product_name);
			TextView  text2 = getViewFromHolder(R.id.item_submit_order_product_price);
			TextView  text3 = getViewFromHolder(R.id.item_submit_order_product_number);
			
			ImageLoader.getInstance().displayImage(itemData.getImage(), image);
			text1.setText(itemData.getName());
			text2.setText("￥"+itemData.getPrice());
			text3.setText("数量x"+itemData.getQuantity());
			
		}
		
	}
	

}
